/**
 * Copyright (c) 2012-2013 YunZhiSheng(Shanghai) Co.Ltd. All right reserved.
 * @FileName : RouteShowSession.java
 * @ProjectName : vui_assistant
 * @PakageName : cn.yunzhisheng.vui.assistant.session
 * @Author : Dancindream
 * @CreateDate : 2013-9-6
 */
package cn.yunzhisheng.vui.assistant.session;

import org.json.JSONObject;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;
import cn.yunzhisheng.common.util.LogUtil;
import cn.yunzhisheng.preference.PrivatePreference;
import cn.yunzhisheng.vui.assistant.baidu.BaiduMap;
import cn.yunzhisheng.vui.assistant.gaode.GaodeMap;
import cn.yunzhisheng.vui.assistant.preference.SessionPreference;
import cn.yunzhisheng.vui.assistant.preference.UserPreference;

/**
 * @Module : 隶属模块名
 * @Comments : 描述
 * @Author : Dancindream
 * @CreateDate : 2013-9-6
 * @ModifiedBy : Dancindream
 * @ModifiedDate: 2013-9-6
 * @Modified: 2013-9-6: 实现基本功能
 */
public class RouteShowSession extends BaseSession {
	public static final String TAG = "RouteShowSession";

	// private RouteContentView mRouteContentView = null;

	/**
	 * @Author : Dancindream
	 * @CreateDate : 2013-9-6
	 * @param context
	 * @param sessionManagerHandler
	 */
	public RouteShowSession(Context context, Handler sessionManagerHandler) {
		super(context, sessionManagerHandler);
	}

	public void putProtocol(JSONObject jsonProtocol) {
		super.putProtocol(jsonProtocol);
		addQuestionViewText(mQuestion);

		JSONObject resultObject = getJSONObject(mDataObject, "result");

		double fromLat = getJsonValue(resultObject, "fromLatitude", 0d);
		double fromLng = getJsonValue(resultObject, "fromLongtitude", 0d);
		String fromCity = getJsonValue(resultObject, "fromCity", "");
		String fromPoi = getJsonValue(resultObject, "fromPosition", "");
		double toLat = getJsonValue(resultObject, "toLatitude", 0d);
		double toLng = getJsonValue(resultObject, "toLongtitude", 0d);
		String toCity = getJsonValue(resultObject, "toCity", "");
		String toPoi = getJsonValue(resultObject, "toPosition", "");
		String originFromPOI = getJsonValue(resultObject, "originFromPOI");
		String poiVendor = PrivatePreference.getValue("poi_vendor",
				UserPreference.MAP_VALUE_AMAP);

		addAnswerViewText(mAnswer);
		playTTS(mTTS);

		if ("AMAP".equals(poiVendor) || "GAODE".equals(poiVendor)) {
			GaodeMap.showRoute(mContext, BaiduMap.ROUTE_MODE_DRIVING, fromLat,
					fromLng, fromCity, originFromPOI, fromPoi, toLat, toLng,
					toCity, toPoi);
		} else if ("BAIDU".equals(poiVendor)) {
			BaiduMap.showRoute(mContext, BaiduMap.ROUTE_MODE_DRIVING, fromLat,
					fromLng, fromCity, fromPoi, toLat, toLng, toCity, toPoi);
		} else {
			Toast.makeText(mContext, "Unsupported map.", Toast.LENGTH_SHORT)
					.show();
		}

		// mSessionManagerHandler.sendEmptyMessage(SessionPreference.MESSAGE_SESSION_DONE);
	}

	@Override
	public void onTTSEnd() {
		LogUtil.d(TAG, "onTTSEnd");
		super.onTTSEnd();
		mSessionManagerHandler
				.sendEmptyMessage(SessionPreference.MESSAGE_SESSION_DONE);
	}
}
